<template>
	<view>
		<view class="header">
			<view class="nav">
				<view class="nav-top">
					<view class="nav-top-one bigtext" v-cloak>
						{{restop.total_price}}
					</view>
					<view class="nav-top-two">
						历史累计奖励
					</view>
				</view>
				<view class="nav-top">
					<view class="nav-top-one bigtext" v-cloak>
						{{restop.total7_price}}
					</view>
					<view class="nav-top-two">
						近七日奖励
					</view>
				</view>
			</view>
			<view class="nexttop">
				<view class="nav-top">
					<view class="nav-top-one" v-cloak>
						{{restop.level}}
					</view>
					<view class="nav-top-two">
						我的等级
					</view>
				</view>
				<view class="nav-top">
					<view class="nav-top-one" v-cloak>
						{{restop.yeji}} 份
					</view>
					<view class="nav-top-two">
						当前业绩
					</view>
				</view>
				<view class="nav-top">
					<view class="nav-top-one" v-cloak>
						{{restop.jicha}}
					</view>
					<view class="nav-top-two">
						业务提成
					</view>
				</view>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="load-more">
			<view class="container">
				<!-- 带上拉加载的数据列表 -->
				<view class="big-loading-text loading-text ">
					<text>订单号</text>
					<text>奖金(元)</text>
					<text>管理费（元）</text>
					<text>极差</text>
					<text>时间</text>
				</view>
				<view v-for="(item,key) in newsList" :key="key" class="loading-text">
					<text v-cloak>{{item.ordersn}}</text>
					<text v-cloak>{{item.price}}</text>
					<text v-cloak>{{item.glfee}}</text>
					<text v-cloak>{{item.rate}}</text>
					<text v-cloak>{{item.time}}</text>
				</view>
			</view>
			<uni-load-more v-if="load == 1" :loadingType="loadingType" :contentText="contentText"></uni-load-more>
		</view>
	</view>
</template>

<script>
	// //下拉刷新插件
	// import yyRefresh from '../../../components/yy-refresh/yy-refresh.nvue';
	import uniLoadMore from '../../../components/uni-load-more.vue';
	var _self,
	page = 1,
	timer = null;
	export default {
		components: {
			// yyRefresh,
			uniLoadMore
		},
		data() {
			return {
				restop:[],
				openid:'',
				active:"active",
				systemInfo:[],
				index:1,
				newsList:[],
				listafter:[],
				loadingText: '加载中...',
				loadingType: 0,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				load: 0,
				page: 1,
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
					this.getnewsList()
					this.concat()
				},
				fail: () => {
					uni.navigateTo({
						url: '../member'
					});
				}
			});
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getnewsList()
		},
		// 上拉加载
		onReachBottom(){
			if (this.timer != null) {
				clearTimeout(this.timer)
			}
			this.timer = setTimeout(()=> {
				this.getmorenews()
			}, 1000);
		},
		methods:{
			setAjax(){
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.ajicha&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						this.restop = res.data
						// console.log(this.restop)
					},
					fail: () => {},
					complete: () => {}
				});
			},
			// 第一次请求数据，刷新
			getnewsList() {
				this.loadingType = 0;
				uni.showNavigationBarLoading();
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=commission.order.get_ajicha&app=1&page=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {                                                
						this.page++;//得到数据之后page+1
						this.newsList = res.data.result.list;
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();//得到数据后停止下拉刷新
						// console.log(this.newsList)
					}
				});
			},
			getmorenews() {
				if (this.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				uni.request({
					url:this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=commission.order.get_ajicha&app=1&page=' + this.page,
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res)=> {
						if (res.data.result.list == '') {//没有数据
							this.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}
						this.page++;//每触底一次 page +1
						this.listafter = res.data.result.list
						console.log(this.listafter)
						this.newsList = this.newsList.concat(this.listafter);//将数据拼接在一起
						// this.$options.methods.concat()
						this.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					}
				});
			},
			concat(){
				const listafterLength = this.listafter.length;    //工资项长度
                const newsListLength = this.newsList.length;     //工资长度
				//先遍历工资项
                for (const i=0; i<listafterLength; i++){
					//取出相同字段value
                    const value = this.listafter[i].value;
					//遍历工资
                    for (const j=0; j<newsListLength; j++){
                        const amount = this.newsList[j][value];
						//如果金额取出来，不是undefined的话，说明字段对应起来的
                        if (amount !== undefined){
                            this.listafter[i].amount = amount;
                            break;
                        }
                    }
                }
			},
			jumpcoin(e){
				var id =e.currentTarget.dataset.id
				uni.navigateTo({
					url: 'mingxi?id='+ id
				});
			},
			jump(e){
				var src =e.currentTarget.dataset.src
				uni.navigateTo({
					url: src
				});
			}
		}
	}
</script>

<style>
.header {
	background-color: #fea23d;
	color: #fff;
	font-weight: 500;
}
.nav {
	display: flex;
}
.nav-top {
	margin: 20upx;
	text-align: center;
	flex: 1;
}
.nav-top-one {
	font-size: 28upx;
}
.bigtext {
	font-size: 41upx;
}
.nav-top-two {
	font-size: 20upx;
}
.nexttop {
	display: flex;
}
.nexttop .nav-top{
	margin: 0;
	margin-bottom: 15upx;
},
.container {
	background-color: #FEA23D;
}
.loading-text {
	margin: ;
	background-color: fff;
	display: flex;
}

.loading-text text:nth-child(1) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 3;
	text-align: center;
	font-size: 20upx;
}
.loading-text text:nth-child(2) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 20upx;
}
.loading-text text:nth-child(3) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 20upx;
}
.loading-text text:nth-child(4) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 20upx;
}
.loading-text text:nth-child(5) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 2;
	text-align: center;
	font-size: 20upx;
}
.all_add {
	height: 80upx;
	text-align: center;
	line-height: 80upx;
	background-color: rgb(254,162,61);
	color: #fff;
}
.big-loading-text {
	font-weight: 550;
	border-bottom: 2upx solid rgb(243,243,243);
}
uni-page-body{height:100%;}
</style>
